const Cart = require("../model/cart/cart")
//购物车列表
exports.list=(req,res)=>{
    let token=req.user
    console.log(token);
    let page=req.params.page
    let limit=req.query.limit?req.query.limit:10
    Cart.getCartList(page,limit,token.id).then(value=>{
        res.js(value)
    })
}
//添加购物车
exports.add=(req,res)=>{
    let token=req.user
    let goods_id=req.body.goods_id
    let goods_skus_id=req.body.goods_skus_id
    let num=req.body.num
    if (!goods_id&&!goods_skus_id&&!num) {
        res.cc("缺少参数")
    }
    Cart.addCart(token.id,goods_id,goods_skus_id,num).then(value=>{
        res.js(true)
    })
}
//删除
exports.delete=(req,res)=>{
    let token=req.user
    let ids=req.body.ids
    Cart.delete(token.id,ids).then(value=>{
        res.js(true)
    })
}
//修改
exports.update=(req,res)=>{
    let token=req.user
    let id=req.params.id
    let goods_skus_id=req.body.goods_skus_id
    Cart.updateGoodsSkusId(token.id,id,goods_skus_id).then(value=>{
        res.js(true)
    })   
}